package remote.controls
{
	import flash.text.TextField;
	
	import remote.geom.EdgeMetrics;
	import remote.geom.Size;
	
	/**
	 * 文本框
	 * @author 银魂飞雪
	 * @createDate 2011-2-26
	 */
	public class Text extends Component
	{
		private var _textField:TextField;
		public function Text()
		{
			super();
		}
		/**
		 * @inheritDoc 
		 * 
		 */
		override protected function createChildren():void
		{
			_textField = new TextField();
			_textField.wordWrap = true;
			addChild(_textField);
		}
		/**
		 * @inheritDoc 
		 * 
		 */
		override protected function updateChildren():void
		{
			var edge:EdgeMetrics = _layout.edge;
			_textField.width = width - edge.left - edge.right;
			_textField.height = height - edge.top - edge.bottom;
			updateLayout();
		}
		/**
		 * @inheritDoc 
		 * 
		 */
		override protected function setMeasureOrExplicitSize():void
		{
			var oldSize:Size = new Size(width, height);
			super.setMeasureOrExplicitSize();
			if(!oldSize.equal(new Size(width, height)))
			{
				updateChildren();
			}
		}
		
		/**
		 * @inheritDoc 
		 * 
		 */
		override public function getMeasureSize():Size
		{
			var edge:EdgeMetrics = _layout.edge;
			var result:Size = new Size(edge.left + edge.right, edge.top + edge.bottom);
			if(_textField.text.length > 0)
			{
				var oldSize:Size = new Size(_textField.width, _textField.height);
				_textField.width = isNaN(_explicitWidth)? Number.MAX_VALUE : this._explicitWidth;
				_textField.height = Number.MAX_VALUE;
				result.width += _textField.textWidth + 6;
				result.height += _textField.textHeight + 6;
				_textField.width = oldSize.width;
				_textField.height = oldSize.height;
			}
			return result;
		}

		
		/**
		 * 文本
		 * 
		 */		
		public function get text():String
		{
			return _textField.text;
		}
		
		public function set text(value:String):void
		{
			if(_textField.text != value)
			{
				_textField.text = value;
				updateSize();
			}
		}
		
		/**
		 * 文本框，设置texfField属性，可通过此属性设置 
		 * 
		 */		
		public function get textField():TextField
		{
			return _textField;
		}
		

	}
}